/*
 * @Author: Vorga
 * @LastEditors: Vorga
 */
#ifndef LINK_DOUBLE_ARRAY_H
#define LINK_DOUBLE_ARRAY_H

#include <stdbool.h>
#include <stdio.h>

#include "node_double.h"

typedef int (*CMP)(const void*, const void*);
typedef void (*FUNC)(const void*);

typedef struct LinkDoubleList {
    NodeDouble* head;
    size_t size;
} LinkDoubleList;

LinkDoubleList* create_dll();

void _add_nd(NodeDouble* prev, NodeDouble* next, void* data);

void _del_nd(NodeDouble* node);

void add_head_dll(LinkDoubleList* list, void* data);

void add_tail_dll(LinkDoubleList* list, void* data);

bool del_head_dll(LinkDoubleList* list);

bool del_tail_dll(LinkDoubleList* list);

NodeDouble* _index_nd(LinkDoubleList* list, size_t index);

NodeDouble* _val_nd(LinkDoubleList* list, void* key, CMP cmp);

void* head_dll(LinkDoubleList* list);

void* tail_dll(LinkDoubleList* list);

bool empty_dll(LinkDoubleList* list);

bool del_index_dll(LinkDoubleList* list, size_t index);

bool del_val_dll(LinkDoubleList* list, void* key, CMP cmp);

bool mod_index_dll(LinkDoubleList* list, size_t index, void* data);

bool mod_val_dll(LinkDoubleList* list, void* old, void* data, CMP cmp);

void traversal_dll(LinkDoubleList* list, FUNC func);

void destory_dll(LinkDoubleList* list);
//排序
void sort_dll(LinkDoubleList* list, CMP cmp);
//查询
void* query_val_dll(LinkDoubleList* list, void* key, CMP cmp);

void* query_index_dll(LinkDoubleList* list, size_t index);
//长度
size_t size_dll(LinkDoubleList* list);
#endif // LINK_DOUBLE_ARRAY_H
